home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / aspisrc.zip / TAR.H < prev    next >
C/C++ Source or Header  |  1992-01-26  |  10KB  |  294 lines

  1. /*
  2.  
  3.     Copyright (C) 1988 Free Software Foundation
  4.  
  5. GNU tar is distributed in the hope that it will be useful, but WITHOUT ANY
  6. WARRANTY.  No author or distributor accepts responsibility to anyone
  7. for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.
  9. Refer to the GNU tar General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute GNU tar,
  12. but only under the conditions described in the GNU tar General Public
  13. License.  A copy of this license is supposed to have been given to you
  14. along with GNU tar so you can know your rights and responsibilities.  It
  15. should be in a file named COPYING.  Among other things, the copyright
  16. notice and this notice must be preserved on all copies.
  17.  
  18. In other words, go ahead and share GNU tar, but don't try to stop
  19. anyone else from sharing it farther.  Help stamp out software hoarding!
  20. */
  21.  
  22. /*
  23.  * Header file for tar (tape archive) program.
  24.  *
  25.  * @(#)tar.h 1.24 87/11/06
  26.  *
  27.  * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  28.  */
  29.  
  30. #include "testpad.h"
  31.  
  32. /* major() and minor() macros (among other things) defined here for hpux */
  33. #ifdef hpux
  34. #include <sys/mknod.h>
  35. #endif
  36.  
  37. /*
  38.  * Kludge for handling systems that can't cope with multiple
  39.  * external definitions of a variable.  In ONE routine (tar.c),
  40.  * we #define TAR_EXTERN to null; here, we set it to "extern" if
  41.  * it is not already set.
  42.  */
  43. #ifndef TAR_EXTERN
  44. #define TAR_EXTERN extern
  45. #endif
  46.  
  47. #if defined(USG) && !defined(XENIX) && !defined(HAVE_SIZE_T)
  48. typedef int size_t;
  49. #endif
  50.  
  51. /*
  52.  * Header block on tape.
  53.  *
  54.  * I'm going to use traditional DP naming conventions here.
  55.  * A "block" is a big chunk of stuff that we do I/O on.
  56.  * A "record" is a piece of info that we care about.
  57.  * Typically many "record"s fit into a "block".
  58.  */
  59. #define    RECORDSIZE    512
  60. #define    NAMSIZ        100
  61. #define    TUNMLEN        32
  62. #define    TGNMLEN        32
  63. #define SPARSE_EXT_HDR  21
  64. #define SPARSE_IN_HDR    4
  65.  
  66. struct sparse {
  67.     char offset[12];
  68.     char numbytes[12];
  69. };
  70.  
  71. struct sp_array {
  72.     int offset;
  73.     int numbytes;
  74. };
  75.  
  76. union record {
  77.     char        charptr[RECORDSIZE];
  78.     struct header {
  79.         char    name[NAMSIZ];
  80.         char    mode[8];
  81.         char    uid[8];
  82.         char    gid[8];
  83.         char    size[12];
  84.         char    mtime[12];
  85.         char    chksum[8];
  86.         char    linkflag;
  87.         char    linkname[NAMSIZ];
  88.         char    magic[8];
  89.         char    uname[TUNMLEN];
  90.         char    gname[TGNMLEN];
  91.         char    devmajor[8];
  92.         char    devminor[8];
  93.         /* these following fields were added by JF for gnu */
  94.         /* and are NOT standard */
  95.         char    atime[12];
  96.         char    ctime[12];
  97.         char    offset[12];
  98.         char    longnames[4];
  99. #ifdef NEEDPAD
  100.         char    pad;
  101. #endif
  102.         struct    sparse sp[SPARSE_IN_HDR];
  103.         char    isextended;
  104.         char    realsize[12];        /* true size of the sparse file */
  105. /*        char    ending_blanks[12];*/    /* number of nulls at the
  106.                            end of the file, if any */
  107.     } header;
  108.     struct extended_header {
  109.         struct sparse sp[21];
  110.         char isextended;
  111.     } ext_hdr;
  112. };
  113.  
  114. /* The checksum field is filled with this while the checksum is computed. */
  115. #define    CHKBLANKS    "        "    /* 8 blanks, no null */
  116.  
  117. /* The magic field is filled with this if uname and gname are valid. */
  118. #define    TMAGIC        "ustar  "    /* 7 chars and a null */
  119.  
  120. /* The linkflag defines the type of file */
  121. #define    LF_OLDNORMAL    '\0'        /* Normal disk file, Unix compat */
  122. #define    LF_NORMAL    '0'        /* Normal disk file */
  123. #define    LF_LINK        '1'        /* Link to previously dumped file */
  124. #define    LF_SYMLINK    '2'        /* Symbolic link */
  125. #define    LF_CHR        '3'        /* Character special file */
  126. #define    LF_BLK        '4'        /* Block special file */
  127. #define    LF_DIR        '5'        /* Directory */
  128. #define    LF_FIFO        '6'        /* FIFO special file */
  129. #define    LF_CONTIG    '7'        /* Contiguous file */
  130. /* Further link types may be defined later. */
  131.  
  132. /* Note that the standards committee allows only capital A through
  133.    capital Z for user-defined expansion.  This means that defining something
  134.    as, say '8' is a *bad* idea. */
  135. #define LF_DUMPDIR    'D'        /* This is a dir entry that contains
  136.                        the names of files that were in
  137.                        the dir at the time the dump
  138.                        was made */
  139. #define LF_MULTIVOL    'M'        /* This is the continuation
  140.                        of a file that began on another
  141.                        volume */
  142. #define LF_NAMES    'N'        /* For storing filenames that didn't
  143.                        fit in 100 characters */
  144. #define LF_SPARSE    'S'        /* This is for sparse files */
  145. #define LF_VOLHDR    'V'        /* This file is a tape/volume header */
  146.                     /* Ignore it on extraction */
  147.  
  148. /*
  149.  * Exit codes from the "tar" program
  150.  */
  151. #define    EX_SUCCESS    0        /* success! */
  152. #define    EX_ARGSBAD    1        /* invalid args */
  153. #define    EX_BADFILE    2        /* invalid filename */
  154. #define    EX_BADARCH    3        /* bad archive */
  155. #define    EX_SYSTEM    4        /* system gave unexpected error */
  156. #define EX_BADVOL    5        /* Special error code means
  157.                        Tape volume doesn't match the one
  158.                        specified on the command line */
  159.  
  160. /*
  161.  * Global variables
  162.  */
  163. TAR_EXTERN union record    *ar_block;    /* Start of block of archive */
  164. TAR_EXTERN union record    *ar_record;    /* Current record of archive */
  165. TAR_EXTERN union record    *ar_last;    /* Last+1 record of archive block */
  166. TAR_EXTERN char        ar_reading;    /* 0 writing, !0 reading archive */
  167. TAR_EXTERN int        blocking;    /* Size of each block, in records */
  168. TAR_EXTERN int        blocksize;    /* Size of each block, in bytes */
  169. TAR_EXTERN char        *ar_file;    /* File containing archive */
  170. TAR_EXTERN char        *info_script;    /* Script to run at end of each tape change */
  171. TAR_EXTERN char        *name_file;    /* File containing names to work on */
  172. TAR_EXTERN char        *tar;        /* Name of this program */
  173. TAR_EXTERN struct sp_array *sparsearray;/* Pointer to the start of the scratch space */
  174. TAR_EXTERN int        sp_array_size;    /* Initial size of the sparsearray */
  175. TAR_EXTERN int         tot_written;    /* Total written to output */
  176. TAR_EXTERN struct re_pattern_buffer
  177.               *label_pattern;    /* compiled regex for extract label */
  178.  
  179. /*
  180.  * Flags from the command line
  181.  */
  182. TAR_EXTERN int cmd_mode;
  183. #define CMD_NONE    0
  184. #define CMD_CAT        1        /* -A */
  185. #define CMD_CREATE    2        /* -c */
  186. #define CMD_DIFF    3        /* -d */
  187. #define CMD_APPEND    4        /* -r */
  188. #define CMD_LIST    5        /* -t */
  189. #define CMD_UPDATE    6        /* -u */
  190. #define CMD_EXTRACT    7        /* -x */
  191. #define CMD_DELETE    8        /* -D */
  192. #define CMD_VERSION    9        /* +version */
  193.  
  194.                     /* -[0-9][lmh] */
  195.             /* CMD_CAT       -A */
  196.                     /* -b */
  197. TAR_EXTERN int    f_reblock;        /* -B */
  198.             /* CMD_CREATE       -c */
  199.                     /* -C */
  200.             /* CMD_DIFF       -d */
  201. /* TAR_EXTERN char    f_dironly;    /* -D */
  202.                     /* -f */
  203. TAR_EXTERN int    f_run_script_at_end;    /* -F */
  204. TAR_EXTERN int     f_gnudump;        /* -G */
  205. TAR_EXTERN int    f_follow_links;        /* -h */
  206. TAR_EXTERN int    f_ignorez;        /* -i */
  207.             /* CMD_DELETE       -J */
  208. TAR_EXTERN int    f_keep;            /* -k */
  209. TAR_EXTERN int    f_startfile;        /* -K */
  210. TAR_EXTERN int    f_local_filesys;    /* -l */
  211. TAR_EXTERN int  tape_length;        /* -L */
  212. TAR_EXTERN int    f_modified;        /* -m */
  213. TAR_EXTERN int     f_multivol;        /* -M */
  214. TAR_EXTERN int    f_new_files;        /* -N */
  215. TAR_EXTERN int    f_oldarch;        /* -o */
  216. TAR_EXTERN int  f_exstdout;        /* -O */
  217. TAR_EXTERN int    f_use_protection;    /* -p */
  218. TAR_EXTERN int  f_absolute_paths;    /* -P */
  219. TAR_EXTERN int    f_sayblock;        /* -R */
  220. TAR_EXTERN int    f_sorted_names;        /* -s */
  221. TAR_EXTERN int    f_sparse_files;        /* -S  ... JK */
  222. TAR_EXTERN int    f_namefile;        /* -T */
  223.             /* CMD_UPDATE       -u */
  224. TAR_EXTERN int    f_verbose;        /* -v */
  225. TAR_EXTERN char *f_volhdr;        /* -V */
  226. TAR_EXTERN int  f_confirm;        /* -w */
  227. TAR_EXTERN int  f_verify;        /* -W */
  228.             /* CMD_EXTRACT     -x */
  229. TAR_EXTERN int  f_exclude;        /* -X */
  230. TAR_EXTERN int     f_compress;        /* -z */
  231.                     /* -Z */
  232. TAR_EXTERN int    f_do_chown;        /* +do-chown */
  233. TAR_EXTERN int  f_totals;        /* +totals */
  234.  
  235. /*
  236.  * We now default to Unix Standard format rather than 4.2BSD tar format.
  237.  * The code can actually produce all three:
  238.  *    f_standard    ANSI standard
  239.  *    f_oldarch    V7
  240.  *    neither        4.2BSD
  241.  * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  242.  * The only advantage to the "neither" option is that we can cmp our
  243.  * output to the output of 4.2BSD tar, for debugging.
  244.  */
  245. #define        f_standard        (!f_oldarch)
  246.  
  247. /*
  248.  * Structure for